#include "Frame.h"

#include "../states/TitleState.h"
#include "Event.h"

Frame::Frame() {
    this->theCurrentState = &(TitleState::getInstance(this));
    this->theRunStatus = false;
	this->theStateSet.insert(this->theCurrentState);
}

void Frame::start() {
    this->theRunStatus = true;
    Event anEvent;
    while(this->theRunStatus == true) {
        this->theCurrentState->draw();
        cin >> anEvent;
		cout << "\n\n\n";
		this->theCurrentState->handle(anEvent);
    }
}

void Frame::stop() {
    this->theRunStatus = false;
	set<State*>::iterator anIterator = this->theStateSet.begin();
	while(anIterator != this->theStateSet.end()) {
		delete *anIterator;
		++anIterator;
	}
}

void Frame::insertState(State *aState) {
	this->theStateSet.insert(aState);
}

void Frame::changeState(State &aState) {
    this->theCurrentState = &aState;
}

void Frame::print(const string &aString) {
    cout << aString << endl;
}

GameData& Frame::getGame() {
	return this->theGameData;
}
